<template>
  <div class="arrymdiv">
    <div class="descriptions">
      <el-descriptions title="课程详情" direction="vertical" :column="3" :size="3" border>
        <el-descriptions-item label="课程名称" min-width="300px"
          ><el-input v-model="kcname" placeholder="名称" v-if="xghidden == true" />
          <p v-if="xghidden == false">vue学习</p></el-descriptions-item
        >

        <el-descriptions-item :span="4" label="描述"
          ><el-input v-model="kcname" placeholder="描述" v-if="xghidden == true" />
          <p v-if="xghidden == false">这是一个vue课程</p></el-descriptions-item
        >
        <el-descriptions-item label="是否公开" :span="1">
          <el-tag v-if="xghidden == false" class="ml-2" type="success">是</el-tag>
          <el-switch v-if="xghidden == true" v-model="ispublic" style="--el-switch-on-color: #13ce66" inline-prompt active-text="是" inactive-text="否"
        /></el-descriptions-item>
        <el-descriptions-item label="角标" min-width="150px" :span="1">
          <span v-if="xghidden == false"> <el-tag class="ml-2" type="danger">热门</el-tag></span>

          <el-select v-model="value" v-if="xghidden == true" multiple placeholder="角标" style="width: 240px">
            <el-option v-for="item in tagoptions" :key="item.value" :label="item.label" :value="item.value" /> </el-select
        ></el-descriptions-item>
        <el-descriptions-item :span="4" label="添加时间" v-if="xghidden == false">2022-7-21 12:00:00</el-descriptions-item>
        <el-descriptions-item :span="4" v-if="xghidden == true" label="修改图片"
          ><el-upload ref="upload" class="upload-demo" action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" :limit="1" :auto-upload="false">
            <template #trigger>
              <el-button type="primary">选择图片</el-button>
            </template>
          </el-upload></el-descriptions-item
        >
        <el-descriptions-item span="4" label="章节">
          <el-button type="primary" class="tablebutton" v-if="xghidden == true" @click="$router.push({ name: 'addchapter' })">新增</el-button>
          <el-table :key="tablekey" :data="tableData" style="width: 100%" :row-style="{ height: '60px' }">
            <el-table-column align="center" type="index" label="序号" width="100" />
            <el-table-column align="center" prop="name" label="章节昵称" />
            <el-table-column align="center" prop="name" label="文件名" />
            <el-table-column fixed="right" v-if="xghidden == true" align="center" label="操作" width="200">
              <template #default>
                <el-button type="danger" size="small">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-descriptions-item>
        <el-descriptions-item label="操作" span="4"
          ><el-button type="success" v-if="xghidden == false" @click="">发布</el-button><el-button type="warning" v-if="xghidden == false" @click="">禁用</el-button
          ><el-button type="primary" v-if="xghidden == false" @click="xg()">修改</el-button><el-button type="danger" v-if="xghidden == false" @click="deletes()">删除</el-button>
          <el-button type="success" v-if="xghidden == true" @click="bcok()">保存</el-button></el-descriptions-item
        >
        <el-descriptions-item v-if="xghidden == false" label="数据统计">
          <div id="chartline" style="height: 500px"></div>
        </el-descriptions-item>
      </el-descriptions>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { reactive, toRefs } from '@vue/reactivity';
import { useRoute } from 'vue-router';
import * as echarts from 'echarts';
import { ElMessage, ElMessageBox } from 'element-plus';
export default defineComponent({
  setup() {
    const data = reactive({
      xghidden: false,
      kcname: '',
      ispublic: '',
      tablekey: false,
      value: '',
      options: {
        title: {
          text: '课程数据统计',
        },
        tooltip: {},
        xAxis: {
          data: ['7.19', '7.20', '7.21', '7.22', '7.23'],
        },
        yAxis: {},
        series: [
          {
            name: '学习量',
            type: 'bar',
            data: [5, 20, 36, 10, 10],
          },
        ],
      },
      tableData: [
        {
          name: '第一次课',
        },
        {
          name: '第二次课',
        },
      ],
      tagoptions: [
        {
          value: '推荐',
          label: '推荐',
        },
        {
          value: '热门',
          label: '热门',
        },
      ],
    });

    const $route = useRoute();
    const xg = () => {
      data.xghidden = true;
      data.tablekey = !data.tablekey;
    };
    const bcok = () => {
      data.xghidden = false;
      ElMessage({
        message: '修改成功',
        type: 'success',
      });
      setTimeout(() => {
        var myChart = echarts.init(document.getElementById('chartline') as HTMLElement);
        // 创建图标
        myChart.setOption(data.options);
      }, 10);
    };
    const deletes = () => {
      ElMessageBox.confirm('确定要删除吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        ElMessage({
          type: 'success',
          message: '删除成功！',
        });
      });
    };
    return {
      ...toRefs(data),
      xg,
      bcok,
      deletes,
    };
  },
  mounted() {
    // 获取DOM元素并且进行初始化
    var myChart = echarts.init(document.getElementById('chartline') as HTMLElement);
    // 创建图标
    myChart.setOption(this.options);
  },
});
</script>
<style scoped>
.descriptions {
  padding: 20px;
}
.arrymdiv {
  border-radius: 10px;
  margin: 1px;
  background-color: rgb(255, 255, 255);
  box-shadow: 1px 1px 5px #cfcfcf;
}
.tablebutton {
  float: right;
}
</style>
